package com.yingran.beiqi.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yingran.beiqi.MenuView
import com.yingran.beiqi.R
import com.yingran.beiqi.activity.mapbox.*
import com.yingran.common.util.dp2px
import com.yingran.common.util.log

/**
 * main界面
 */
class MainActivity : BaseActivity(), View.OnClickListener {
    enum class Menus(val label: String, val resId: Int) {
        SignsDetection("SignsDetection", R.drawable.sign_clas),
        Segmentation("Segmentation", R.drawable.ic_section_segmentation),
        ObjectDetection("ObjectDetection", R.drawable.ic_section_object_detector),
        LaneDetection("LaneDetection", R.drawable.icon_png),
        CollisionDetection("CollisionDetection", R.drawable.ic_section_collision_detection),
        ObjectMapping("ObjectMapping", R.drawable.ic_section_object_mapping),
        ARRouting("ARRouting", R.drawable.ic_section_routing),
        Navigation("Navigation", R.drawable.ic_section_routing),
        ChinaMap("ChinaMap", R.drawable.ic_section_routing),

        CheDaoTanCe("车道探测", R.drawable.ic_section_routing),
        QianCheYuJing("前车预警", R.drawable.ic_section_routing),
        DuiXiangTanCe("对象探测", R.drawable.ic_section_routing),
        Test("Test", R.drawable.ic_section_object_mapping);

        override fun toString(): String {
            return "Menus(label='$label', resId=$resId)"
        }
    }

    private val menus = arrayOf(
            Menus.SignsDetection,
            Menus.Segmentation,
            Menus.ObjectDetection,
            Menus.LaneDetection,
            Menus.CollisionDetection,
            Menus.ObjectMapping,
            Menus.ChinaMap,
//            Menus.ARRouting,
            Menus.Test)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "主页"
        headBar.setLeftIconVisible(false)
        initView()
    }

    private fun initView() {
        val contentLayout = findViewById<LinearLayout>(R.id.contentLayout)
        for (menu in menus) {
            var menuView = MenuView(context, menu)

            menuView.setOnClickListener(this@MainActivity)
            val layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
            layoutParams.setMargins(0, dp2px(15), 0, dp2px(15))
            contentLayout.addView(menuView, layoutParams)
        }
    }

    override fun onClick(v: View?) {
        if (v is MenuView) {
            log(v.menu.toString())
//            if (!SupportedSnapdragonBoards.isBoardSupported(SystemInfoUtils.getSnpeSupportedBoard())) {
//                var noticeDialog = NoticeDialog(context)
//                noticeDialog.setMsg("The device is not supported")
//                noticeDialog.setOnClickListener { dialog ->
//                    dialog.dismiss()
//                }
//                noticeDialog.show()
//                return
//            }


            val intent: Intent = when {
                v.menu == Menus.SignsDetection -> Intent(this@MainActivity, SignsDetectionActivity::class.java)
                v.menu == Menus.Segmentation -> Intent(this@MainActivity, SegmentationActivity::class.java)
                v.menu == Menus.ObjectDetection -> Intent(this@MainActivity, ObjectDetectionActivity::class.java)
                v.menu == Menus.LaneDetection -> Intent(this@MainActivity, LaneDetectionActivity::class.java)
                v.menu == Menus.CollisionDetection -> Intent(this@MainActivity, CollisionDetectionActivity::class.java)
                v.menu == Menus.Test -> Intent(this@MainActivity, MapActivity::class.java)
                v.menu == Menus.ChinaMap -> Intent(this@MainActivity, SimpleChinaMapViewActivity::class.java)
                else -> Intent(this@MainActivity, TestActivity::class.java)
            }
            startActivity(intent)
        }
    }
}
